import { defineStore } from 'pinia'
import { selectUserMenu } from '@/api/authApi.js'
export const useAuthStore = defineStore('auth', {
  state() {
    return {
      currentUser: null,
      token: null,
      menus: [],
      activeTitle: '',
    }
  },
  actions: {
    async initMenus() {
      let menus = await selectUserMenu()
      this.menus = menus
    },

    // 使用pinia...mapAction辅助方法拉取useAuthStore中的clearStore实现复用
    clearStore() {
      this.currentUser = null
      this.token = null
      this.menus = []
    },
  },
  // 启用插件持久化 => 自动加载本地存储中的持久化数据
  persist: true,
})
